package com.ruoyi.generator.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.generator.common.query.Query;
import com.ruoyi.generator.domain.FieldTypeEntity;
import com.ruoyi.generator.service.FieldTypeService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Set;

/**
 * 字段类型管理
 */
@RestController
@RequestMapping("gen/fieldtype")
@AllArgsConstructor
public class FieldTypeController extends BaseController {
    private final FieldTypeService fieldTypeService;

    @GetMapping("page")
    public TableDataInfo page(Query query) {
        return getDataTable(fieldTypeService.page(query));
    }

    @GetMapping("{id}")
    public R<FieldTypeEntity> get(@PathVariable("id") Long id) {
        FieldTypeEntity data = fieldTypeService.getById(id);

        return R.ok(data);
    }

    @GetMapping("list")
    public R<Set<String>> list() {
        Set<String> set = fieldTypeService.getList();

        return R.ok(set);
    }

    @PostMapping
    public R<String> save(@RequestBody FieldTypeEntity entity) {
        fieldTypeService.save(entity);

        return R.ok();
    }

    @PutMapping
    public R<String> update(@RequestBody FieldTypeEntity entity) {
        fieldTypeService.updateById(entity);

        return R.ok();
    }

    @DeleteMapping
    public R<String> delete(@RequestBody Long[] ids) {
        fieldTypeService.removeBatchByIds(Arrays.asList(ids));

        return R.ok();
    }
}